package com.alice.router.guigu;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.Vector;
import java.util.concurrent.CompletableFuture;

/**
 * @author alice
 * @date 2021/12/24
 * @apiNote
 */
public class TestString {
    public static void main(String[] args) throws InterruptedException {
        Vector<Thread> threadVector = new Vector<>();
        TestString a = new TestString();
        String str = new String();

        for (int i = 0; i < 100; i++) {
            StringThread childThread = new StringThread();
            childThread.setName("thread"+i);
            threadVector.add(childThread);
            childThread.start();
            System.out.println(childThread.getName()+"-----"+childThread.getStr().length());
            str=childThread.getStr();
        }
        for (Thread thread:threadVector){
            thread.join();
        }
        System.out.println("-----"+str.toString().length());

    }

//    private static void extracted() throws InterruptedException {
//        Vector<Thread> threadVector = new Vector<>();
//        TestString a = new TestString();
//        StringBuilder str = new StringBuilder();
//
//        for (int i = 0; i < 10; i++) {
//            Thread childThread = new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    a.append(str);
//                }
//            },"thread"+i
//            );
//            threadVector.add(childThread);
//            childThread.start();
//            System.out.println(childThread.getName()+"--add----"+str.toString().length());
//        }
//        for (Thread thread:threadVector){
//            thread.join();
//        }
//        System.out.println("-----"+str.toString().length());
//    }

    public String append(String str){
//        System.out.println("之前"+str);
        str+="1";
//        System.out.println("之后"+str);
        str=str.substring(1);
//        System.out.println("delete----"+str);
        return str;
    }
}
